home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / transpor / ifmail23.z / ifmail23 / ifmail / iflib / sequencer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-08  |  506 b   |  31 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <sys/types.h>
  4. #include <time.h>
  5. #include "lutil.h"
  6. #include "config.h"
  7.  
  8. unsigned long sequencer(void)
  9. {
  10.     FILE *fp;
  11.     struct flock fl;
  12.     unsigned long id;
  13.  
  14.     time((time_t*)&id);
  15.  
  16.     if ((fp=fopen(sequence,"r+")) == NULL)
  17.         fp=fopen(sequence,"w");
  18.     if (fp == NULL) return id;
  19.     fl.l_type=F_WRLCK;
  20.     fl.l_whence=0;
  21.     fl.l_start=0L;
  22.     fl.l_len=0L;
  23.     fcntl(fileno(fp),F_SETLKW,&fl);
  24.     fscanf(fp,"%lu",&id);
  25.     rewind(fp);
  26.     fprintf(fp,"%lu\n",++id);
  27.     fclose(fp);
  28.  
  29.     return id;
  30. }
  31.